﻿
// 创建人  ：LinJian
// 创建时间：2007年5月24日
using System;
using System.Collections.Generic;
using System.Data.OracleClient;
using System.Text;
using WF_Business;
using WF_DataAccess;

namespace ExtBusiness.CommonBusiness
{
    /// <!--
    /// 功能描述  : 生成全局ID
    /// 创建人  : LinJian
    /// 创建时间: 2007年5月24日
    /// -->
    public struct GenerateGuid
    {
        /// <summary>
        /// 获取新的全局id
        /// </summary>
        public static string NewGuid
        {
            get
            {
                return Guid.NewGuid().ToString();
            }
        }

        /// <summary>
        /// 获取oracle生成的guid
        /// </summary>
        public static string NewOracleGuid
        {
            get
            {
                String strSql = "select sys_guid() as guid from dual connect by rownum=1";

                System.Data.IDataReader idrTemp = SysParams.OAConnection().GetDataReader(strSql);

                string strReturn = string.Empty;
                if (idrTemp.Read())
                {
                    byte[] bArr =(byte[])idrTemp["guid"];      
           
                    strReturn = Encoding.ASCII.GetString(bArr); 
                }
                return strReturn;
            }
        }

        /// <summary>
        /// 执行存储过程(向表单插入数据)
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="strIid"></param>
        public static void InsertDataToTable(string strTableName, string strIid)
        {
            OracleParameter param1 = new OracleParameter();
            param1.ParameterName = "tableName";
            param1.DbType = System.Data.DbType.String;
            param1.Value = strTableName;

            OracleParameter param2 = new OracleParameter();
            param2.ParameterName = "iid";
            param2.DbType = System.Data.DbType.String;
            param2.Value = strIid;

            OracleParameter param3 = new OracleParameter();
            param3.ParameterName = "inputIndex";
            param3.DbType = System.Data.DbType.String;
            param3.Value = 0;

            System.Data.IDataParameter[] paramArray = new OracleParameter[3];
            paramArray[0] = param1;
            paramArray[1] = param2;
            paramArray[2]=param3;
            SysParams.OAConnection().RunProc("Base.InsertDataToTable", ref paramArray);
        }

        /// <summary>
        /// 执行存储过程(向表单插入数据)
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="strIid"></param>
        /// <param name="daParam"></param>
        public static void InsertDataToTable(string strTableName, string strIid, IDataAccess daParam)
        {
            OracleParameter param1 = new OracleParameter();
            param1.ParameterName = "tableName";
            param1.DbType = System.Data.DbType.String;
            param1.Value = strTableName;

            OracleParameter param2 = new OracleParameter();
            param2.ParameterName = "iid";
            param2.DbType = System.Data.DbType.String;
            param2.Value = strIid;

            OracleParameter param3 = new OracleParameter();
            param3.ParameterName = "inputIndex";
            param3.DbType = System.Data.DbType.String;
            param3.Value = 0;

            System.Data.IDataParameter[] paramArray = new OracleParameter[3];
            paramArray[0] = param1;
            paramArray[1] = param2;
            paramArray[2]=param3;

            daParam.RunProc("Base.InsertDataToTable", ref paramArray);
        }
    }
}
